package com.homework;

import java.util.Random;
import java.util.Scanner;

public class demo13 {
    public static void main(String[] args) {
        //定义一个char类型的数组，长度为a-z，A-Z，0-9的个数：62
        char[] arr = new char[62];
        //定义索引
        int index = 0;
        //遍历数组，逐一存入
        for (char j = 'a'; j <= 'z'; j++) {
            arr[index++] = j;
        }
        for (char j = 'A'; j <= 'Z'; j++) {
            arr[index++] = j;
        }
        for (char j = '0'; j <= '9'; j++) {
            arr[index++] = j;
        }
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要生成的验证码位数：");
        int num = sc.nextInt();
        //随机数
        Random r = new Random();
        for (int k = 0; k <= num; k++) {
            //随机数生成索引
            int code = r.nextInt(1, 63);
            System.out.print(arr[code]);
        }
    }
}